const axios = require('axios')
const fs = require("fs")

// echo音乐

async function getPage(num){
    let httpUrl = 'http://www.app-echo.com/api/recommend/sound-day?page=' + num;
    let res = await axios.get(httpUrl)
    res.data.list.forEach((item) => {
        let title = item.sound.name;
        let mp3Url = item.sound.source;
        download(mp3Url, title)
    })
}

async function download(mp3Url, title) {
    let res = await axios.get(mp3Url, { responseType: 'stream' })
    let path = fs.createWriteStream('./mp3/' + title + '.mp3')
    res.data.pipe(path)
    res.data.on('close', () => {
        path.close()
    })
}

getPage(1)